package com.insyte.model;

import android.content.SharedPreferences;
import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.Gson;
import com.insyte.config.Constants;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by T430 on 6/22/2015.
 */
public class User implements Parcelable {
    String id, email, first_name, last_name, token;
    String number, gender, age, height, story;
    String dating_status = "", str_image = "";
    String interest;// = list.toArray(new String[list.size()]);
    List<Category> lsInterestFB = new ArrayList<Category>();
    String profile_picture;

    public String getDating_status() {
        return dating_status;
    }

    public String getInterest() {
        return interest;
    }

    public List<Category> getLsInterestFB() {
        return lsInterestFB;
    }

    public void setLsInterestFB(List<Category> lsInterestFB) {
        this.lsInterestFB = lsInterestFB;
    }

    public void setInterest(String interest) {
        this.interest = interest;
    }

    public void setDating_status(String dating_status) {
        this.dating_status = dating_status;
    }

    public String getStr_image() {
        return str_image;
    }

    public void setStr_image(String str_image) {
        this.str_image = str_image;
    }

    public User() {
        this.id = "";
        this.email = "";
        this.first_name = "";
        this.last_name = "";
        this.token = "";
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirst_name() {
        return first_name;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public String getLast_name() {
        return last_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getStory() {
        return story;
    }

    public void setStory(String story) {
        this.story = story;
    }

    public String getProfile_picture() {
        return profile_picture;
    }

    public void setProfile_picture(String profile_picture) {
        this.profile_picture = profile_picture;
    }

    // for parcelable
    @Override
    public int describeContents() {
        return 0;
    }

    public User(Parcel parcel) {
        id = parcel.readString();
        email = parcel.readString();
        first_name = parcel.readString();
        last_name = parcel.readString();
        token = parcel.readString();
        number = parcel.readString();
        gender = parcel.readString();
        age = parcel.readString();
        height = parcel.readString();
        story = parcel.readString();
        profile_picture = parcel.readString();
        parcel.readTypedList(lsInterestFB, Category.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(id);
        parcel.writeString(email);
        parcel.writeString(first_name);
        parcel.writeString(last_name);
        parcel.writeString(token);
        parcel.writeString(number);
        parcel.writeString(gender);
        parcel.writeString(age);
        parcel.writeString(height);
        parcel.writeString(story);
        parcel.writeString(profile_picture);
        parcel.writeTypedList(lsInterestFB);
    }

    public static final Creator<User> CREATOR = new Creator<User>() {
        @Override
        public User createFromParcel(Parcel parcel) {
            return new User(parcel);
        }

        @Override
        public User[] newArray(int i) {
            return new User[i];
        }
    };

    public void saveUserInformation(SharedPreferences preference) {
        SharedPreferences.Editor prefsEditor = preference.edit();
        Gson gson = new Gson();
        String json = gson.toJson(this);
        prefsEditor.putString(Constants.KEY_USER_LOGIN, json);
        prefsEditor.commit();
    }

    public static User getUserInformation(SharedPreferences preference) {
        try {
            Gson gson = new Gson();
            String json = preference.getString(Constants.KEY_USER_LOGIN, "");
            User obj = gson.fromJson(json, User.class);
            if (obj == null)
                obj = new User();
            return obj;
        } catch (Exception ex) {
            ex.printStackTrace();
            return new User();
        }
    }

}
